<?php
class STE_Photo extends STE_Media
{	
	public function getPhotoCountByAlbumType($albumID)
	{
		$r = $this->_fetchStatement("CALL sp_admin_get_photo_count(?)", array($albumID));
		return empty($r) ? null : $r[0]; 
	}
	
	public function getPhoto($photoID)
	{
		$r = $this->_fetchStatement("CALL sp_admin_get_photo(?)", array($photoID));
		return empty($r) ? null : $r[0];
	}

	public function getPhotoList($albumID, $from, $numberOfPhotos)
	{
		return $this->_fetchStatement("CALL sp_admin_get_photo_list(?, ?, ?)", array($albumID, $from, $numberOfPhotos));
	}

	public function insertPhoto($albumID, $fileName, $photoDescription)
	{	
		$returnArray = $this->_moveTempFileToMediaFolder($fileName);
		if(!isset($returnArray['successful']) || !$returnArray['successful']) {
			return false;
		}
			
		return $this->_executeStatement("CALL sp_admin_insert_photo(?, ?, ?, ?, ?, ?, ?, ?)", 
										array(
											$albumID,
											self::MEDIA_URL_PREFIX . $returnArray['realFileName'],
											$returnArray['realWidth'],
											$returnArray['realHeight'],
											self::MEDIA_URL_PREFIX . $returnArray['thumbnailFileName'],											
											$returnArray['thumbnailWidth'],
											$returnArray['thumbnailHeight'],
											$photoDescription));
	}
	
	public function deletePhoto($photoID)
	{	
		// get media row before delete it
		$media = $this->getPhoto($photoID);
	
		// Delete photo from server.		
		$successful = $this->_deleteMediaFile($this->_getFileNameFromFilePath($media['path']), 
											  $this->_getFileNameFromFilePath($media['thumbnail_path']));		
		if(!$successful) {
			return false;
		}
		return $this->_executeStatement("CALL sp_admin_delete_photo(?)", 
										array($photoID));	
	}
		
	public function updatePhoto($mediaID, $mediaDescription)
	{
		return $this->_executeStatement("CALL sp_admin_update_photo(?, ?)", 
										array($mediaID,
											  $mediaDescription));
	}
}	
?>